package com.wang.tool.common;

import java.util.LinkedHashMap;
import java.util.Map;

/**
 * @Author wangshaopeng
 * @Date 2022/5/15
 */
public class LruMap<K, V> extends LinkedHashMap<K, V> {
    private static final long serialVersionUID = -3609506601737385735L;

    /**
     * 最大存储量
     */
    private int maxSize;

    public LruMap() {
        super();
        this.maxSize = 10000;
    }

    public LruMap(int maxSize) {
        super();
        this.maxSize = maxSize;
    }

    public LruMap(int initCap, int maxSize) {
        super(initCap, 0.75f, true);
        this.maxSize = maxSize;
    }


    @Override
    protected boolean removeEldestEntry(Map.Entry<K, V> eldest) {
        return size() > maxSize;
    }


    public int getMaxSize() {
        return maxSize;
    }

    public void setMaxSize(int maxSize) {
        this.maxSize = maxSize;
    }

}
